package com.hq.fxh.No0_ChengQu.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;


import com.hq.fxh.No5_User.MyModle.Activity.item.BannerAdContentItem;
import com.hq.fxh.No5_User.MyModle.Activity.item.BannerAdItem;
import com.hq.fxh.No5_User.MyModle.Activity.item.BigAdContentItem;
import com.hq.fxh.No5_User.MyModle.Activity.item.CardAdComtentItem;
import com.hq.fxh.No5_User.MyModle.Activity.item.GraphicAdContentItem;
import com.hq.fxh.No5_User.MyModle.Activity.item.QQAdContentItem;
import com.hq.fxh.No5_User.MyModle.Activity.item.QRCodeAdContentItem;
import com.hq.fxh.No5_User.MyModle.Activity.item.StoreAdContentItem;
import com.hq.fxh.No5_User.MyModle.Activity.item.TiePianAdContentItem;
import com.hq.fxh.No5_User.MyModle.AdBannerInfo;
import com.hq.fxh.No5_User.MyModle.AdPagerAdapter;
import com.hq.fxh.No5_User.MyModle.Config;

import java.util.Collections;
import java.util.List;

/**
 * @author 大圣
 * @ClassName AdTemplateContentAdapter
 * @Description :
 * @Created 2015/12/22 0022
 * @Email qwqe601660957@163.com
 */
public class AdTemplateContentAdapter extends AdPagerAdapter {
    private List<AdBannerInfo> adInfos;
    private Context mContext;
    private View.OnClickListener listener;
    public AdTemplateContentAdapter(Context context, List<AdBannerInfo> data){
        super();
        mContext = context;
        adInfos = data;
    }
    @Override
    public View getView(int position, View convertView, final ViewGroup container) {
        final View view = convertView;
        final AdBannerInfo adInfo = adInfos.get(position);
        int type = adInfo.getAdvert_type_id();
        if(type == Config.AdTypeCode.AD_BANNER){
            /** 通栏广告 */
            BannerAdContentItem bannerAdContentItem = null;
            if(view == null){
                bannerAdContentItem = new BannerAdContentItem(mContext);
            }else{
                bannerAdContentItem = (BannerAdContentItem) view;
            }
            bannerAdContentItem.showAdInfo(adInfo);
            bannerAdContentItem.setOnClickListener(listener);
            return bannerAdContentItem;
        }else if(type == Config.AdTypeCode.AD_GRAPHIC){
            /** 图文广告 */
            GraphicAdContentItem graphicAdContentItem = null;
            if(view == null){
                graphicAdContentItem = new GraphicAdContentItem(mContext);
            }else{
                graphicAdContentItem = (GraphicAdContentItem) view;
            }
            graphicAdContentItem.showAdInfo(adInfo);
            graphicAdContentItem.setOnClickListener(listener);
            return graphicAdContentItem;
        }else if(type == Config.AdTypeCode.AD_CARD){
            /** 名片广告 */
            CardAdComtentItem cardAdComtentItem = null;
            if(view == null){
                cardAdComtentItem = new CardAdComtentItem(mContext);
            }else{
                cardAdComtentItem = (CardAdComtentItem) view;
            }
            cardAdComtentItem.showAdInfo(adInfo);
            cardAdComtentItem.setOnClickListener(listener);
            return cardAdComtentItem;
        }else if(type == Config.AdTypeCode.AD_QR_CODE){
            /** 二维码广告 */
            QRCodeAdContentItem qrCodeAdContentItem = null;
            if(view == null){
                qrCodeAdContentItem = new QRCodeAdContentItem(mContext);
            }else{
                qrCodeAdContentItem = (QRCodeAdContentItem) view;
            }
            qrCodeAdContentItem.showAdInfo(adInfo);
            qrCodeAdContentItem.setOnClickListener(listener);
            return qrCodeAdContentItem;
        }else if(type == Config.AdTypeCode.AD_QQ){
            /** QQ广告 */
            QQAdContentItem qqAdContentItem = null;
            if(view == null){
                qqAdContentItem = new QQAdContentItem(mContext);
            }else{
                qqAdContentItem = (QQAdContentItem) view;
            }
            qqAdContentItem.showAdInfo(adInfo);
            qqAdContentItem.setOnClickListener(listener);
            return qqAdContentItem;
        }else if(type == Config.AdTypeCode.AD_Store){
            /** 店铺广告 */
            StoreAdContentItem storeAdContentItem = null;
            if(view == null){
                storeAdContentItem = new StoreAdContentItem(mContext);
            }else{
                storeAdContentItem = (StoreAdContentItem) view;
            }
            storeAdContentItem.showAdInfo(adInfo);
            storeAdContentItem.setOnClickListener(listener);
            return storeAdContentItem;
        }
        else if(type == Config.AdTypeCode.AD_TiePian){//
            /** 贴片广告 */
            TiePianAdContentItem tiePianoAdContentItem = null;
            if(view == null){
                tiePianoAdContentItem = new TiePianAdContentItem(mContext);
            }else{
                tiePianoAdContentItem = (TiePianAdContentItem) view;
            }
            tiePianoAdContentItem.showAdInfo(adInfo);
            tiePianoAdContentItem.setOnClickListener(listener);
            return tiePianoAdContentItem;
        }
        else if(type == Config.AdTypeCode.AD_BIG_BANNER){//
            /** 大图通栏广告 */
            BigAdContentItem bigAdContentItem = null;
            if(view == null){
                bigAdContentItem = new BigAdContentItem(mContext);
            }else{
                bigAdContentItem = (BigAdContentItem) view;
            }
            bigAdContentItem.showAdInfo(adInfo);
            bigAdContentItem.setOnClickListener(listener);
            return bigAdContentItem;
        }
        return new BannerAdItem(mContext);
    }
    @Override
    public int getCount() {
        return adInfos.size();
    }
    public AdBannerInfo getItem(int position){
        return adInfos.get(position);
    }
    public void setAdInfos(List<AdBannerInfo> data){
        if(data == null || data.isEmpty())
            return;
        adInfos.clear();
        adInfos.addAll(data);
        notifyDataSetChanged();
    }
    public void setList(List<AdBannerInfo> data){
        this.adInfos = data;
    }

    public void setAdInfos(AdBannerInfo[] data){
        if(data == null || data.length == 0)
            return;
        adInfos.clear();
        Collections.addAll(adInfos, data);
        notifyDataSetChanged();
    }
    public List<AdBannerInfo> getList(){

        return adInfos;
    }
    public void addAll(List<AdBannerInfo> data) {
        if (data == null || data.isEmpty())
            return;
        adInfos.addAll(data);
        notifyDataSetChanged();
    }

    public void addAll(AdBannerInfo[] data) {
        if (data == null || data.length == 0)
            return;
        Collections.addAll(adInfos, data);
        notifyDataSetChanged();
    }

    public void setOnClickListener(View.OnClickListener listener){
        this.listener = listener;
    }
}
